package generator.website;

import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import CarProject.*;
import CarProject.impl.*;;

public class creationScript
{
  protected static String nl;
  public static synchronized creationScript create(String lineSeparator)
  {
    nl = lineSeparator;
    creationScript result = new creationScript();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = " ";
  protected final String TEXT_2 = "\t" + NL + "create table ";
  protected final String TEXT_3 = NL + "(" + NL + "\t";
  protected final String TEXT_4 = " ";
  protected final String TEXT_5 = " not null," + NL + "\t";
  protected final String TEXT_6 = "primary key(";
  protected final String TEXT_7 = ")" + NL + ");" + NL + "\t" + NL + "\t" + NL + "" + NL + "\t";
  protected final String TEXT_8 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
     Table laTable = (Table) argument;
    EList<VueGenerale> listChamps = laTable.getPossede();
    stringBuffer.append(TEXT_1);
    String type=null;
    stringBuffer.append(TEXT_2);
    stringBuffer.append(laTable.getNom());
    stringBuffer.append(TEXT_3);
    for (int i = 0;i<listChamps.size();i++){
	if(((ChampsImpl)laTable.getPossede().get(i)).getType().getValue()== EnumType.VARCHAR){ type = "String"; } else { type = "long"; }
	
    stringBuffer.append(((ChampsImpl)laTable.getPossede().get(i)).getNom());
    stringBuffer.append(TEXT_4);
    stringBuffer.append(((ChampsImpl)laTable.getPossede().get(i)).getType().toString());
    stringBuffer.append(TEXT_5);
    }
    stringBuffer.append(TEXT_6);
    stringBuffer.append(laTable.getClePrimaire().getChamps().getNom());
    stringBuffer.append(TEXT_7);
    stringBuffer.append(TEXT_8);
    return stringBuffer.toString();
  }
}
